<template>
  <div style="height: calc(100vh - 8px - 7rem);width: 100%;">
    <div class="indicator">
      <div class="indicator-title">
        <span>周期性数据统计</span>
      </div>
      <div class="indicator-month">
        <!-- <el-date-picker v-model="month[0]" type="month" class="month" placeholder="开始月"></el-date-picker>~
        <el-date-picker v-model="month[1]" type="month" class="month" placeholder="结束月"></el-date-picker>-->
        <el-date-picker v-model="formData.start" type="month" class="month" placeholder="开始月"></el-date-picker>~
        <el-date-picker v-model="formData.end" type="month" class="month" placeholder="结束月"></el-date-picker>
        <el-button @click="selTime">查询</el-button>
      </div>

      <!--取水量 制水量-->
      <div class="indicator-main dash-box">
        <div v-for="(item,index) in indicator" :key="index">
          <div class="title">{{ item.title }}</div>
          <ul class="main">
            <li v-for="(it,i) in item.data" :key="i">
              <div class="label">{{ it.label }}</div>
              <div :class="'value value-'+i">{{ it.value }}</div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- 水质达标汇总 -->
    <water-qulity></water-qulity>

    <!-- 产销差和单位制水成本 -->
    <product-poor></product-poor>

    <!-- 中间地图及相关信息 -->
    <div class="map">
      <ul class="topList">
        <li>
          管网总长度:
          <span>161.59km</span>
        </li>
        <li>
          服务总人口:
          <span>29.4万人</span>
        </li>
        <li>
          供水总面积:
          <span>62.2km²</span>
        </li>
      </ul>
      <div class="list" style="top: 10%;left: 5%;">
        <div class="title">北郊水厂供水区</div>
        <div>
          本期供水量:
          <span>140478</span>m³
        </div>
        <div>
          上期供水量:
          <span>152767</span>m³
        </div>
        <div style="margin-top: .25rem;">
          压力最低值:
          <span>0.21</span>Mpa
        </div>
        <div class="color" style="margin-top: .25rem;">
          管网总长度:
          <span>29.79</span>km
        </div>
        <div class="color">
          服务总人口:
          <span>5.4</span>万人
        </div>
        <div class="color">
          供水总面积:
          <span>7.75</span>km²
        </div>
        <i class="l t"></i>
        <i class="l b"></i>
        <i class="r t"></i>
        <i class="r b"></i>
        <b class="l t"></b>
        <b class="l b"></b>
        <b class="r t"></b>
        <b class="r b"></b>
      </div>
      <div class="list" style="bottom: 10%;right: 5%;">
        <div class="title title-2">东郊水厂供水区</div>
        <div>
          本期供水量:
          <span>1248366</span>m³
        </div>
        <div>
          上期供水量:
          <span>1256449</span>m³
        </div>
        <div style="margin-top: .25rem;">
          压力最低值:
          <span>0.14</span>Mpa
        </div>
        <div class="color" style="margin-top: .25rem;">
          管网总长度:
          <span>131.8</span>km
        </div>
        <div class="color">
          服务总人口:
          <span>24</span>万人
        </div>
        <div class="color">
          供水总面积:
          <span>54.45</span>km²
        </div>
        <i class="l t"></i>
        <i class="l b"></i>
        <i class="r t"></i>
        <i class="r b"></i>
        <b class="l t"></b>
        <b class="l b"></b>
        <b class="r t"></b>
        <b class="r b"></b>
      </div>
    </div>

    <!-- 销售回收率汇总一系列图表 -->
    <sales-recovery></sales-recovery>
  </div>
</template>

<script>
import Echarts from "@/components/echarts/index";
import bottomDashboard from "./components/bottomDashboard";

import WaterQulity from "./components/WaterQulity";
import ProductPoor from "./components/ProductPoor";
import SalesRecovery from "./components/SalesRecovery";

import { overview, overview2 } from "@/api/dashboard"; // 不同模块的api 分开放，
export default {
  name: "Dashboard",
  components: {
    Echarts,
    bottomDashboard,
    WaterQulity,
    ProductPoor,
    SalesRecovery
  },
  mounted() {
    const that = this;
    overview({}).then(res => {
      var resultData = res.data.adsKpiAlls;
      console.log(resultData);
      // 处理拿到的数据理拿到的数据
      var newArray = [];
      if (resultData.length > 0) {
        for (let i = 0; i < resultData.length; i++) {
          const newA = {},
            newB = [];
          newA.title = resultData[i].title;
          newB.push(
            {
              label: resultData[i].rateTitle,
              value: resultData[i].rate + "%"
            },
            {
              label: resultData[i].valueTitle,
              value: resultData[i].value
            },
            {
              label: resultData[i].planValueTitle,
              value: resultData[i].planValue
            }
          );
          newA.data = newB;
          console.log(newB);
          console.log(newA);
          newArray.push(newA);
        }
        console.log(newArray);
        this.indicator = newArray;
      } else {
        console.log("error submit!!");
        return false;
      }
    });
  },
  data() {
    return {
      month: ["2018-12-31T16:00:00.000Z", "2019-05-31T16:00:00.000Z"],
      isShow: [],
      indicator: null,
      formData: {
        start: "",
        end: ""
      },
      tableData: {}
    };
  },
  methods: {
    //选择时间查询功能
    selTime() {
      //alert(1)
      const that = this;
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      setTimeout(() => {
        loading.close();
      }, 800);

      // let data = {
      //   start_data: this.formData.start,
      //   end_data: this.formData.end
      // };
      // 月份和日 不足两位数时补0
      // 定义 zeroize方法
      function zeroize(obj) {
        if (obj < 10) {
          return "0" + obj;
        } else {
          return obj;
        }
      }
      //时间戳转换
      function formarDate(param) {
        let now = new Date(param);
        let year = now.getFullYear(); //年
        let month = zeroize(now.getMonth()+1); //月
        //let day = zeroize(now.getDate());
        //return year + "-" + month + "-" + day;
        return year + "-" + month;
      }
      //查询传给后端的时间参数
      let data = {
        start_data: formarDate(this.formData.start),
        end_data: formarDate(this.formData.end)
      };
      console.log(data);
      //调接口查询数据
      overview2(data).then(res => {
        // const that = this;
        // alert(222);
        // console.log(res);
        // if (res.data.code == 200) {
        //   this.tableData = res.data.adsKpiAlls;
        //   //this.page.totalCount = res.data.data.total_size;
        // } else {
        //   this.tableData = [];
        //   //this.page.totalCount = 0;
        // }
        var resultData = res.data.adsKpiAlls;
        console.log(resultData);
        // 处理拿到的数据理拿到的数据
        var newArray = [];
        if (resultData.length > 0) {
          for (let i = 0; i < resultData.length; i++) {
            const newA = {},
              newB = [];
            newA.title = resultData[i].title;
            newB.push(
              {
                label: resultData[i].rateTitle,
                value: resultData[i].rate + "%"
              },
              {
                label: resultData[i].valueTitle,
                value: resultData[i].value
              },
              {
                label: resultData[i].planValueTitle,
                value: resultData[i].planValue
              }
            );
            newA.data = newB;
            console.log(newB);
            console.log(newA);
            newArray.push(newA);
          }
          console.log(newArray);
          this.indicator = newArray;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.map {
  position: absolute;
  top: 0.5rem;
  left: calc(26vw + 0.5rem);
  right: calc(26vw + 0.5rem);
  bottom: calc(23% + 0.5rem);
  overflow: hidden;
  background: url("./img/pic_Map_main.png") no-repeat center;
  background-size: auto 110%;
  span {
    font-size: 1.3em;
    margin: 0 5px;
  }
  .list {
    position: absolute;
    background: rgba(0, 0, 0, 0.1);
    font-size: 0.8rem;
    padding: 0.5rem 1.5rem 0.5rem 2rem;
    line-height: 1.3;
    .title {
      line-height: 1.4;
      margin-bottom: 0.2rem;
      font-size: 1rem;
      color: #00ccff;
      &:before {
        content: "";
        position: absolute;
        width: 16px;
        height: 16px;
        border-radius: 100%;
        border: 2px solid #cc66ff;
        background: #6600cc;
        top: calc(1.2rem - 8px);
        left: 0.7rem;
      }
      &.title-2:before {
        content: "";
        position: absolute;
        width: 16px;
        height: 16px;
        border-radius: 100%;
        border: 2px solid #ff3333;
        background: #663300;
        top: calc(1.2rem - 8px);
        left: 0.7rem;
      }
    }
    .color {
      color: #00ccff;
    }
    i,
    b {
      width: 1px;
      height: 20px;
      position: absolute;
      background: #00ccff;
      &.l {
        left: 0;
      }
      &.t {
        top: 0;
      }
      &.r {
        right: 0;
      }
      &.b {
        bottom: 0;
      }
    }
    b {
      height: 1px;
      width: 20px;
    }
  }
}
.home-echarts-bar-box {
  position: absolute;
  width: 26vw;
  right: 0.5rem;
  top: 0.5rem;
  bottom: 0.5rem;
  overflow-x: auto;
  .home-echarts-bar {
    cursor: pointer;
    z-index: 2;
    height: 28vh;
    position: relative;
    margin-bottom: 1rem;
    .dash-box {
      height: 100%;
      .title {
        height: 2rem;
        text-align: center;
        line-height: 2rem;
      }
      .echart {
        height: calc(100% - 2rem);
        padding: 0.5rem;
        &-inner {
          height: 235.714%;
          width: 230.77%;
          transform: scale(0.433333, 0.42424242);
          transform-origin: 0 0;
        }
      }
      &.on {
        position: fixed;
        top: 15vh;
        transform: none !important;
        width: 60vw;
        height: 66vh;
        right: 50%;
        margin-bottom: -27vh;
        margin-right: -30vw;
        border-radius: 2px;
        border: 2px solid rgba(27, 164, 226, 0.85);
        background: rgba(24, 10, 67, 0.95);
        z-index: 4;
        &:before {
          opacity: 0;
          transition: opacity 0.3s;
        }
        .mask {
          display: block;
        }
        .title {
          height: 4rem;
          line-height: 4rem;
          font-size: 1.5rem;
        }
        transform: none !important;
        width: 60vw;
        height: 66vh;
        .echart {
          &-inner {
            height: 100%;
            width: 100%;
            transform: none;
          }
        }
      }
      .mask {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.1);
        z-index: -1;
      }
    }
    .el-icon-circle-close-outline {
      position: absolute;
      top: -16px;
      right: -16px;
      font-size: 24px;
      width: 32px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      color: #dddddd;
      &:hover {
        color: #fff;
      }
      &:after {
        content: "";
        position: absolute;
        width: 20px;
        height: 20px;
        border-radius: 100%;
        background: rgba(24, 10, 67, 0.95);
        top: 6px;
        left: 6px;
        z-index: -1;
      }
    }
  }
}

.echarts-item {
  &-0 {
    bottom: calc(66% + 0.5rem + 5vh);
  }
  &-1 {
    bottom: calc(33% + 0.5rem + 2.5vh);
  }
  &-2 {
    bottom: 0.5rem;
  }
}

.indicator {
  position: absolute;
  left: 0.5rem;
  top: -1.5rem;
  width: 26vw;
  height: 65%;
  &-title {
    display: flex;
    span {
      font-size: 1rem;
      line-height: 1.2rem;
      padding: 0.5rem 1.5rem 0.5rem 0.5rem;
      background: url("./img/Icon_Irregularrectangle_head.png") no-repeat center
        left;
      background-size: 100% 100%;
    }
  }
  .value-0 {
    color: #ff33ff;
  }
  .value-1 {
    color: #33ff33;
  }
  .value-2 {
    color: #ffcc33;
  }
  &-month {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0.5rem;
    .month {
      width: calc(50% - 50px);
    }
  }
  &-main {
    height: calc(100% - 7rem);
    > div {
      height: 25%;
      padding-top: 0.3rem;
      position: relative;
      .title {
        font-size: 0.825rem;
        height: 25%;
        display: flex;
        align-items: center;
        color: #00ffff;
        padding-left: 0.8rem;
      }
      .main {
        height: 70%;
        display: flex;
        align-items: center;
        padding: 0.3rem 0;
        li {
          height: 100%;
          width: calc(100% / 3 - 0.666667px);
          position: relative;
          margin-left: 1px;
          &:after {
            content: "";
            display: block;
            position: absolute;
            width: 1px;
            top: 20%;
            right: -1px;
            height: 60%;
            background: #00beea;
          }
          &:last-child:after {
            content: none;
          }
          .label {
            height: 45%;
            display: flex;
            justify-content: center;
            font-size: 0.75rem;
          }
          .value {
            height: 65%;
            display: flex;
            justify-content: center;
            font-size: 1.5rem;
          }
        }
      }
      &:after {
        content: "";
        display: block;
        height: 1px;
        width: 84%;
        position: absolute;
        background: #00ccff;
        left: 8%;
        bottom: -1px;
      }
      &:last-child:after {
        content: none;
      }
    }
  }
}

.quality {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  width: 26vw;
  height: 36%;
  &-title {
    font-size: 1rem;
    line-height: 2.4rem;
    padding-left: 0.5rem;
    background: #192790;
  }
  &-main {
    width: 133.3333%;
    transform: scale(0.75, 0.75);
    height: calc(133.3333% - 3.4rem);
    transform-origin: 0 0;
  }
}

.marketing {
  padding: 1rem;
  position: absolute;
  left: 28.5%;
  bottom: 0.5rem;
  width: 43%;
  height: 23%;
  display: flex;
  .marketing-item {
    width: 50%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .left {
      margin-right: 0.5rem;
      width: 14vh;
      height: 100%;
    }
    .right {
      padding-bottom: 1.2rem;
    }
  }
}

.dash-box {
  border: 1.2px solid #00ccff;
  background: rgba(0, 0, 255, 0.15);
  box-shadow: 0 0 0.5rem #1800ff;
}

.echarts-item {
  height: 100%;
  .echarts-title {
    text-align: center;
    font-size: 1.3rem;
    height: 2.6rem;
    line-height: 1.8rem;
  }
}

.topList {
  display: flex;
  li {
    width: 33.33%;
    color: #00ccff;
    font-size: 1.1rem;
    span {
      font-size: 1.3rem;
      color: #33ff33;
    }
    &:last-child span {
      color: #ffcc33;
    }
    &:first-child span {
      color: #ff33ff;
    }
  }
}
</style>
<style rel="stylesheet/scss" lang="scss">
.month {
  .el-input__inner {
    padding-right: 0 !important;
  }
}

.el-table thead.is-group th,
.el-table,
.el-table__expanded-cell,
.el-table th,
.el-table tr {
  background: transparent;
}

.el-table,
.el-table thead {
  font-size: 1.2rem;
  color: #fff;
  text-align: center;
}

.el-table thead {
  color: #e78a20;
  text-align: center;
}

.el-table .cell {
  text-align: center;
}

.el-table--enable-row-hover .el-table__body tr:hover > td {
  background: rgba(255, 255, 255, 0.15);
}

.el-progress--circle .el-progress__text {
  font-size: 2rem !important;
  color: #ff33ff;
}
</style>
